package com.shiwaixiangcun.customer.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shiwaixiangcun.customer.Common;
import com.shiwaixiangcun.customer.R;
import com.shiwaixiangcun.customer.entity.HouseSelectListBean;
import com.shiwaixiangcun.customer.utils.SharePreference;

import java.util.List;


/**
 * @author Administrator
 * @date 2016/7/13
 */
public class SelfDialogListAdapter extends BaseAdapter {
    private List<HouseSelectListBean> list;


    public SelfDialogListAdapter(List<HouseSelectListBean> list) {
        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mViewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_self_dialog, null);
            mViewHolder = new ViewHolder();
            mViewHolder.rlSelectHouseA = convertView.findViewById(R.id.rl_select_house_a);
            mViewHolder.ivSelectY = convertView.findViewById(R.id.iv_select_y);
            mViewHolder.ivSelectN = convertView.findViewById(R.id.iv_select_n);
            mViewHolder.tvHouseTitle = convertView.findViewById(R.id.tv_house_title);

            convertView.setTag(mViewHolder);
        } else {
            mViewHolder = (ViewHolder) convertView.getTag();
        }
        final ViewHolder finalMViewHolder = mViewHolder;
        String stringSpParams = SharePreference.getStringSpParams(parent.getContext(), Common.ISSELECTHOSE, Common.SISELECTHOSE);


        mViewHolder.tvHouseTitle.setText(list.get(position).getNumberDesc());
        if (stringSpParams.equals(position + "")) {
            finalMViewHolder.ivSelectY.setVisibility(View.VISIBLE);
            finalMViewHolder.ivSelectN.setVisibility(View.GONE);
        } else {
            finalMViewHolder.ivSelectY.setVisibility(View.GONE);
            finalMViewHolder.ivSelectN.setVisibility(View.VISIBLE);
        }


        return convertView;
    }

    static class ViewHolder {
        RelativeLayout rlSelectHouseA;
        ImageView ivSelectY;
        ImageView ivSelectN;
        TextView tvHouseTitle;
    }

}
